
namespace go media

struct ProtocolOption{
    /**是否开启转换为hls*/
    1: bool enable_hls,
    /**是否开启MP4录制*/
    2: bool enable_mp4,
    /**是否开启转换为rtsp/webrtc*/
    3: bool enable_rtsp,
    /**是否开启转换为rtmp/flv*/
    4: bool enable_rtmp,
    /**是否开启转换为http-ts/ws-ts*/
    5: bool enable_ts,
    /**是否开启转换为http-fmp4/ws-fmp4*/
    6: bool enable_fmp4,

    /**转协议是否开启音频*/
    7: bool enable_audio,
    /**添加静音音频，在关闭音频时，此开关无效*/
    8: bool add_mute_audio,
}


struct AddStreamProxyParam{
    /*结构化中心的目标流的app*/
    1: string destApp,
    /*结构化中心的目标流的stream*/
    2: string destStream,
    /*媒体中心的IP地址*/
    3: string sourceIP,
    /*媒体中心的端口*/
    4: i32 sourcePort,
    /*媒体中心的源流的app*/
    5: string sourceApp,
    /*媒体中心的源流的stream*/
    6: string sourceStream,
	7: i32 retry_count,
	8: ProtocolOption deviceType,
    9: string tid,
}

struct DelStreamProxyParam{
    1: string key,
    2: string tid,
}

/*通用答复*/
struct CommonResponse
{
    1:  i32 code,
    2:  string msg,
}

struct GetStreamStatusRequest
{
    1: string tid,

    /*为空表示所有*/
    2: string app,
    
    /*为空表示所有*/
    3: string stream,

}

struct StreamStatResponse
{
    1:  i32 code,
    2:  string msg,
    3:  i32 totalReaderCount,
    4:  string app,
    5:  string stream,
}

struct OpenRtpServerRequest
{
    1:  i32 port,
    2:  bool isEhome2,
    3:  string streamId,
    4:  bool enableTcp,
    5:  string tid,
}

struct OpenRtpServerResponse
{
    1:  i32 code,
    2:  string msg,
    3:  i32 port,
    4:  string streamId,
    5:  bool enableTcp,
}

struct MergeStreamRect
{
    1: i32 x,
    2: i32 y,
    3: i32 width,
    4: i32 height,
    5: string playUrl,
}

struct StartMergeStreamRequest
{
    1: string tid,
    2: i32 width,
    3: i32 height,
    4: list<MergeStreamRect> childRect,
    5: i32 ssrc,
    /*是否阻塞等待合流结果，如果合流任务大，可能导致请求timeout*/
    6: bool syncWaitResult,
    /*供内部使用,thrift调用者忽略该值。将合流任务分配到哪个GPU卡*/
    7: i32 gpuCardIndex,
}

struct StartMergeStreamResponse
{
    1:  i32 code,
    2:  string msg,
    3:  string ssrc,
}

struct GetMergeStreamStatusRequest
{
    1: string ssrc,
    2: string tid,
}

enum CmdStatus
{
    Unknown,
    FailedToStart,
    Running,
    Finished,
}

struct GetMergeStreamStatusResponse
{
    1: i32 code,
    2: string msg,
    3: string ssrc,
    4: CmdStatus status,
    5: string cmdStatusTip,
}

struct StopMergeStreamRequest
{
    1: string ssrc,
    2: string tid,
}

struct StopMergeStreamResponse
{
    1: i32 code,
    2: string msg,
}

struct JobTimeAbsolute {
    1: i32 year,
    2: i32 month,
    3: i32 day,
    4: i32 hour,
    5: i32 minute,
    6: i32 second,
    7: i32 milliSecond,
}

struct JobServerInfo
{
    1: string serverIp,
    2: i32 serverPort,
    3: string otherInfo,
}

struct RealtimeSnapshotJob
{
    1: JobTimeAbsolute jobTime,
    2: string imageName,
    3: list<JobServerInfo> serverInfo,
}

enum EnumSnapshotJobStatus
{
    Unknown,
    WaitingToSnapshot,
    WaitingToDownload,
    WaitingToSend,
    SendSuccess,
    SendFailedWithoutRetry,
    WaitingToSendAgain,
}

struct SnapshotJobStatus
{
    1: JobTimeAbsolute jobTime,
    2: i32 offsetMillisecond,
    3: string imageName,
    4: list<JobServerInfo> serverInfo,
    5: EnumSnapshotJobStatus jobStatus,
}

struct AddRealtimeSnapshotRequest
{
    1: string tid,
    2: string groupId,
    3: string app,
    4: string stream,
    5: bool sendSnapshotToServer,
    6: list<RealtimeSnapshotJob> allJobs,
}

struct DelSnapshotRequest
{
    1: string tid,
    2: list<string> allGroupId,
    3: string app,
    4: string stream,
}

struct QuerySnapshotStatusRequest
{
    1: string tid,

    /**如果为空，则返回url对应的最近的groupId*/
    2: string groupId,

    /**groupId和app/stream不能同时为空*/
    3: string app,
    4: string stream,
}

struct QuerySnapshotStatusResponse
{
    /**200-查询成功并且有job； 204-查询成功但是没有job*/
    1: i32 code,
    2: string msg,
    3: string groupId,
    4: string app,
    5: string stream,
    6: bool sendSnapshotToServer,
    7: bool isRealtime,
    /**未执行的job列表*/
    8: list<SnapshotJobStatus> allJobsStatus,
}

struct HistorySnapshotJob
{
    1: i32 offsetMillisecond,
    2: string imageName,
    3: list<JobServerInfo> serverInfo,
}

struct AddHistorySnapshotRequest
{
    1: string tid,
    2: string groupId,
    3: string app,
    4: string stream,
    5: bool sendSnapshotToServer,    
    6: list<HistorySnapshotJob> allJobs,
}

struct AddSnapshotResponse
{
    1:  i32 code,
    2:  string msg,
}

/**接入中心与媒体中心的thrift通信接口*/
service MediaServer{

    /**向媒体中心推流*/
    CommonResponse addStreamProxy(1: AddStreamProxyParam request),
	
	/**停止向媒体中心推流*/
    CommonResponse delStreamProxy(1: DelStreamProxyParam request),
	
    /**获取所有流的用户统计数据*/
    list<StreamStatResponse> getStreamStatus(1: GetStreamStatusRequest request),

    /**国标推流需要调用该接口传入streamId*/
    OpenRtpServerResponse openRtpServer(1: OpenRtpServerRequest request),

    /**合并视频流，请求非阻塞*/
    StartMergeStreamResponse startMergeStream(1: StartMergeStreamRequest request),

    /**查询合并视频流命令的运行状态*/
    GetMergeStreamStatusResponse getMergeStreamStatus(1: GetMergeStreamStatusRequest request),

    /**结束合并视频流*/
    StopMergeStreamResponse stopMergeStream(1: StopMergeStreamRequest request),

    /**实时预览-添加抓图任务*/
    AddSnapshotResponse addRealtimeSnapshot(1: AddRealtimeSnapshotRequest request),

    /**历史回调-添加抓图任务*/
    AddSnapshotResponse addHistorySnapshot(1: AddHistorySnapshotRequest request),

    /**实时预览或者历史回调-删除抓图任务*/
    CommonResponse delSnapshot(1: DelSnapshotRequest request),

    /**实时预览或者历史回调-查询抓图任务*/
    QuerySnapshotStatusResponse querySnapshot(1: QuerySnapshotStatusRequest request),

}



